package javaJob.exercise.primary.array;

public class primary7 {
    public static void main(String[] args) {
        int[] digits = {9};
        int[] digits2 = {8,9,9,9};
        int[] answer = plusOne(digits2);
        for (int i=0;i<answer.length;i++){
            System.out.print(answer[i]);
        }
    }

    static int[] plusOne(int[] digits) {
        for (int i=digits.length-1;i>=0;i--){
            if (digits[i]+1 <= 9){
                digits[i]+=1;

                System.out.println(1);

                break;
            }else if (digits[i]+1 >9){
                System.out.println(2);
                if (i==0){
                    int[] temp = new int[digits.length+1];
//                    System.out.println("-"+digits.length);
                    digits[i]=0;
                    temp[0]=1;
                    System.arraycopy(digits, 0, temp, 1, temp.length - 1);
                    digits = temp;
//                    System.out.println("--"+digits.length);
//                    for (int l=0;l<digits.length;l++){
//                        System.out.println("---"+l);
//                        System.out.println("----"+digits[l]);
//                    }
                }else {
                    digits[i]=0;
                }
            }
        }
        return digits;
    }
}
